package com.atguigu.dao.impl;

import com.atguigu.dao.DockerServiceConfigDao;
import com.atguigu.pojo.DockerServiceConfig;

import java.util.List;

public class DockerServiceConfigDaoImpl extends BaseDao implements DockerServiceConfigDao {
    @Override
    public int addDockerServiceConfig(DockerServiceConfig dockerServiceConfig) {
        System.out.println("DockerServiceConfigDaoImpl 程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_dockerServiceConfig(`id`,`serverId`,`serviceId`,`graph`,`bip`) values(?,?,?,?,?);";
            return update(sql,dockerServiceConfig.getId(),dockerServiceConfig.getServerId(),
                    dockerServiceConfig.getServiceId(),dockerServiceConfig.getGraph(),
                    dockerServiceConfig.getBip());
    }

    @Override
    public int deleteDockerServiceConfigById(String id) {
        String sql="delete from t_dockerServiceConfig where id=?";
        return update(sql,id);
    }

    @Override
    public int updateDockerServiceConfig(DockerServiceConfig dockerServiceConfig) {
        String sql="update t_dockerServiceConfig set `serverId`=?,`serviceId`=?,`graph`=?,`bip`=? where id=?";
        return update(sql,dockerServiceConfig.getServerId(),
                dockerServiceConfig.getServiceId(),dockerServiceConfig.getGraph(),
                dockerServiceConfig.getBip(),dockerServiceConfig.getId());
    }

    @Override
    public DockerServiceConfig queryDockerServiceConfigById(String id) {
        String sql ="select `id`,`serverId`,`serviceId`,`graph`,`bip` from t_dockerServiceConfig where id=?";
        return queryForOne(DockerServiceConfig.class,sql,id);
    }

    @Override
    public List<DockerServiceConfig> queryDockerServiceConfigs() {
        String sql ="select `id`,`serverId`,`serviceId`,`graph`,`bip`  from t_dockerServiceConfig";
        return queryForList(DockerServiceConfig.class,sql);
    }
    @Override
    public DockerServiceConfig queryDockerServiceConfigByServiceId(String serviceId){
        String sql ="select `id`,`serverId`,`serviceId`,`graph`,`bip` from t_dockerServiceConfig where serviceId =?";
        return queryForOne(DockerServiceConfig.class,sql,serviceId);
    }


    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from t_dockerServiceConfig";
        Number serverCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverCount.intValue();
    }

    @Override
    public List<DockerServiceConfig> queryForPageItems(Integer begin, Integer pageSize) {
        String sql ="select `id`,`serverId`,`serviceId`,`graph`,`bip` from t_dockerServiceConfig limit ?,?";
        return queryForList(DockerServiceConfig.class,sql,begin,pageSize);

    }
}
